package com.xyht.sca_s.student_manage_system.common.util;

import io.swagger.annotations.ApiModelProperty;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Component;

import java.lang.reflect.Field;

@Component
public class ApiModelUtil {

    public String getFieldValueByFieldName (Class<?> c,String fieldName) {
        String fieldValue = null;
        Field[] declaredFields = c.getDeclaredFields();
        // 3.遍历属性，获取属性上ApiModelProperty的值，属性的名，存入Properties
        if (declaredFields.length != 0) {
            for (Field field : declaredFields) {
                if (field.getAnnotation(ApiModelProperty.class) != null) {
                    if (field.getName().equals(fieldName)){
                        fieldValue = field.getAnnotation(ApiModelProperty.class).value();
                        break;
                    }
                }
            }
        }
        return fieldValue;
    }

}
